import pandas as pd
from sklearn.impute import SimpleImputer
import numpy as np
from sklearn.impute import KNNImputer

df1 = pd.read_csv("D:\数据挖掘\数据预处理-两次实验\数据预处理-实验1\house_train.csv",usecols=['id','distirct','built_date','green_rate','area','floor','oriented','traffic','shockproof','school','crime_rate','pm25','price'])
#显示缺失的属性
result=df1.isna().sum()
print(result)

#mean imputation
df = pd.read_csv("D:\数据挖掘\数据预处理-两次实验\数据预处理-实验1\house_train.csv",usecols=['green_rate','crime_rate'])
imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
X1=imp_mean.fit_transform(df)
print("mean imputation\n",X1)

#KNN imputation
imp_KNN = KNNImputer(n_neighbors=2)
imp_KNN=imp_KNN.fit(df)
X2=imp_KNN.transform(df)
print("KNN imputation\n",X2)


